<?php
class UsersMaster{

	function __construct(){
		
	}

	function __destruct(){

	}


	public function getUsersDetail($id=NULL){
		//Logger::log("Enter: AdminMaster::getAdminDetail() | Args: ");
		if(!empty($id)) $where = " where a.id ";
		$qry = "select * from user a left join user_details b on a.id=b.user_id ".$where." order by a.added desc";
		$rs = MyDB::$db->Execute($qry);
	
		$categories = array();
	
		while ($row=$rs->fetchRow()) {
			$users[]=$row;
		}
		return $users;
		//Logger::log("Exit: AdminMaster::getAdminDetail()");
	}
	public function userStatusUpdate($id,$status=1){
		if(empty($id)) return;
		$Query = "update user set status=".MyDB::$db->qstr($status)." where id=".MyDB::$db->qstr($id);
		 MyDB::$db->Execute($Query);
	}
	public function userDelete($id){
		if(empty($id)) return;
		$Query = "delete from user where id=".MyDB::$db->qstr($id);
		 MyDB::$db->Execute($Query);
		 $Query = "delete from user_details where user_id=".MyDB::$db->qstr($id);
		 MyDB::$db->Execute($Query);
	}
	public function userUpdate($params){
		if(!empty($params[user_id])) return;
		if(!self::checkUserEmail($params[id],$params[email_id])){
			return false;
		}else{
			$Query = "update user set first_name=".MyDB::$db->qstr($params[first_name]).",last_name=".MyDB::$db->qstr($params[last_name]).",email_id=".MyDB::$db->qstr($params[email_id]).",mobile_no=".MyDB::$db->qstr($params[mobile_no]).",
			is_email_varified=".MyDB::$db->qstr($params[is_email_varified]).",is_mobile_varified=".MyDB::$db->qstr($params[is_mobile_varified]).",status=".MyDB::$db->qstr($params[status]).",modified=now() where id=".MyDB::$db->qstr($params[id]);
			MyDB::$db->Execute($Query);
			$Query = "update user_details set address=".MyDB::$db->qstr($params[address]).",dob=".MyDB::$db->qstr($params[dob]).",city=".MyDB::$db->qstr($params[city]).",state=".MyDB::$db->qstr($params[state])."
			,country=".MyDB::$db->qstr($params[country]).",profession=".MyDB::$db->qstr($params[profession]).",gender=".MyDB::$db->qstr($params[gender]).",marital_status=".MyDB::$db->qstr($params[marital_status])."
			,marriage_panning=".MyDB::$db->qstr($params[marriage_panning]).",anniversary_date=".MyDB::$db->qstr($params[anniversary_date]).",interests=".MyDB::$db->qstr($params[interests]).",likes_dislikes=".MyDB::$db->qstr($params[likes_dislikes]).",modified=now() where user_id=".MyDB::$db->qstr($params[id]);
			MyDB::$db->Execute($Query);
			return true;
		}
	}
	public function checkUserEmail($id,$email){
		//Logger::log("Enter: AdminMaster::getAdminDetail() | Args: ");
		
		$qry = "select id from user where email_id=".MyDB::$db->qstr($email)." and id<>".MyDB::$db->qstr($id)." ";;
		$rs = MyDB::$db->Execute($qry);
		if( $rs ){
			$arr = $rs->fetchRow();
			return true;
		}
		return false;
		
		//Logger::log("Exit: AdminMaster::getAdminDetail()");
	}
}	
?>